package com;


import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import connection.DBConnection;

import dao.DBManipulation;

/**
 * Servlet implementation class RegisterServlet2
 */
@WebServlet("/RegisterServlet2")
public class RegisterServlet2 extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public RegisterServlet2() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		
		

	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		DBConnection dbc=new DBConnection();	
		 Connection con=dbc.getNewConnection();
		 Statement st = null;
		 ResultSet rs = null;

		PrintWriter out = response.getWriter();
		//RegisterBean bean=new RegisterBean();
		//bean.setPan(request.getParameter("pann"));
		String a = request.getParameter("pann");
		String a0 = request.getParameter("or");
     String a1 = request.getParameter("mv");
     String a2 = request.getParameter("ad");
     String a3 = request.getParameter("ct");
     String a4 = request.getParameter("ds");
     String a5 = request.getParameter("st");
     String a6 = request.getParameter("pn");
     String a7 = request.getParameter("pr");
     String a8 = request.getParameter("desg");
     try 
		{
			st = con.createStatement();
		}
		catch (SQLException e) 
		{
			e.printStackTrace();
		}

		
		String insertreg = "insert into register2(org_name,mvat,address,city,dist,state,pin,autho_person,designation)" + " values('" + a0+ "','" + a1 + "','" + a2 + "','" + a3 + "','" + a4 + "','" + a5 + "','" + a6 + "','" + a7 + "','" + a8 + "')";
				
		try 
		{
			int i = st.executeUpdate(insertreg);	
			
			if(i>0)
			{
				out.print("<font color=green>Data Saved Successfully....Click 'Go To Login Page'</font>");
			}
			else
	           out.print("Sorry..!! Got an exception.");
		}
		catch (SQLException e) 
		{
			e.printStackTrace();
		}  
	}

}
